<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:c="http://java.sun.com/jsp/jstl/core">

    <body>

        <ui:composition template="./../template.xhtml">
            <ui:define name="meta">
                <c:if test="${user != null}">
                    <c:if test="${user.isAdmin == false}">
                        <meta http-equiv="refresh" content="0; URL=#{facesContext.externalContext.requestContextPath}/faces/403error.xhtml" />
                    </c:if>
                </c:if>
                <c:if test="${user == null}">
                    <meta http-equiv="refresh" content="0; URL=#{facesContext.externalContext.requestContextPath}/faces/login.xhtml" />
                </c:if>
            </ui:define>
            <ui:define name="title">
                Admin List User
            </ui:define>

            <ui:define name="content">

                <f:view>
                    <h:form>
                        <h1><h:outputText value="List User:"/></h1>
                        <p:dataTable value="#{userController.items}" var="item" tableStyle="width:auto" id="userinfo"
                                     rowsPerPageTemplate="5,10,15"
                                     rows="10"
                                     paginator="true"
                                     paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                                     emptyMessage="No cars found with given criteria">
                            <p:column filterBy="#{item.userID}" filterMatchMode="contains">
                                <f:facet name="header">
                                    <h:outputText value="UserID"/>
                                </f:facet>
                                <h:outputText value="#{item.userID}"/>
                            </p:column>
                            <p:column filterBy="#{item.userName}">
                                <f:facet name="header">
                                    <h:outputText value="UserName"/>
                                </f:facet>
                                <h:outputText value="#{item.userName}"/>
                            </p:column>
                            
                            <p:column  filterBy="#{item.email}">
                                <f:facet name="header">
                                    <h:outputText value="Email"/>
                                </f:facet>
                                <h:outputText value="#{item.email}"/>
                            </p:column>
                            <p:column filterBy="#{item.phoneNumber}">
                                <f:facet name="header">
                                    <h:outputText value="PhoneNumber"/>
                                </f:facet>
                                <h:outputText value="#{item.phoneNumber}"/>
                            </p:column>
                            <p:column >
                                <f:facet name="header">
                                    <h:outputText value="BirthDay"/>
                                </f:facet>
                                <h:outputText value="#{item.birthDay}">
                                    <f:convertDateTime pattern="dd/MM/yyyy" />
                                </h:outputText>
                            </p:column>
                            <p:column sortBy="#{item.isDelete}" >
                                <f:facet name="header">
                                    <h:outputText value="De-activate"/>
                                </f:facet>
                                <p:selectBooleanCheckbox value="#{item.isDelete}" disabled="true" />
                            </p:column>
                            <p:column>
                                <p:commandButton image="ui-icon ui-icon-search" action="#{userController.prepareView}" title="View Details" ajax="false">
                                    <f:setPropertyActionListener value="#{item}" target="#{userController.user}"/>
                                </p:commandButton>
                                <p:commandButton image="ui-icon ui-icon-close"
                                                 ajax="false"
                                                 title="De-Activate"
                                                 rendered="#{!item.isDelete}"
                                                 action="#{userController.delete}"
                                                 />
                                <p:commandButton image="ui-icon-check"
                                                 title="Re-Activate"
                                                 ajax="false"
                                                 rendered="#{item.isDelete}"
                                                 action="#{userController.restore}"/>

                            </p:column>

                        </p:dataTable>
                    </h:form>
                </f:view>
            </ui:define>

        </ui:composition>

     
    </body>
</html>
